package com.sanda.bailin.pojo;

import lombok.Data;

import java.util.List;
import java.util.SequencedCollection;

@Data
public class BaseResponse<T> {
    private int code; // 状态码
    private String message; // 消息
    private T data; // 数据

    private Integer count;

    public BaseResponse(int code, String message, T data, Integer count) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.count = count;
    }

    // 省略getter和setter方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 可以添加一些静态方法，用来快速构建响应
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(0, "操作成功", data, 0);
    }

    // 可以添加一些静态方法，用来快速构建响应
    public static <T> BaseResponse<T> success(T data, Integer count) {
        return new BaseResponse<>(0, "操作成功", data, count);
    }

    public static <T> BaseResponse<T> success(String message, T data) {
        return new BaseResponse<>(200, message, data, 0);
    }

    public static <T> BaseResponse<T> success(String message, T data, Integer count) {
        return new BaseResponse<>(200, message, data, count);
    }

    public static <T> BaseResponse<T> fail(int code, String message) {
        return new BaseResponse<>(code, message, null, 0);
    }

    public static <T> BaseResponse<T> fail(String message) {
        return new BaseResponse<>(500, message, null, 0);
    }
}